<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <!-- table区域-begin -->
    <vxe-grid
      ref='xGrid'
      v-bind='vexConfig'
      :align='left'
      :border='true'
      :checkbox-config="checkboxConfig"
      :columns='columns'
      :data='dataSource'
      :height='pageHeight-seachHeight-94'
      :loading='loading'
      :resizable='true'
      :showOverflow='true'
      :toolbar-config="tableToolbar"
      size='mini'
      @checkbox-change='selectChangeEvent'
      @checkbox-all="selectChangeEvent"
    >
      <template #toolbar_buttons>
        <div class='table-operator'>
          <a-button type="primary"  @click="handleAdd">新增</a-button>
          <a-button type="primary" @click="downExportXls('dmsCustProductRule_service')">导出</a-button>
        </div>
      </template>
        <div slot="filterCustType" slot-scope="text,recode">
          {{ text|filterCustType }}
        </div>
      <template  #action='{ row,rowIndex }'>
        <a v-has="'getGoodsAdress:update'" @click='handleEdit(row)'>编辑</a>
        <a-divider type='vertical' />
        <a-dropdown>
          <a class='ant-dropdown-link'>更多
            <a-icon type='down' />
          </a>
          <a-menu slot='overlay'>
            <a-menu-item>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                <a>删除</a>
              </a-popconfirm>
            </a-menu-item>
            <a-menu-item v-has="'business:log'">
<!--              <a href='javascript:' @click='handleBusiness("门店管理",row)'>日志</a>-->
              <a v-has="'business:log'" href='javascript:' @click='handleBusiness("门店管理",row)'>日志</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>

      </template>
        <template #pager>
          <vxe-pager
            :currentPage.sync='ipagination.current'
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :page-size.sync='ipagination.pageSize'
            :pageSizes='ipagination.pageSizeOptions'
            :total='ipagination.total'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
    </vxe-grid>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <contractAdd ref="modalForm" @ok="modalFormOk"></contractAdd>
    <business-log ref="businessLog"></business-log>

  </a-card>
</template>

<script>
import JSuperQuery from '@/components/cn-form/JSuperQuery.vue'
import JInput from '@/components/cn-form/JInput.vue'
import { initDictOptions, filterDictText, filterDictTextByCache } from '@/components/dict/CnDictSelectUtil'
import { PageListMixin } from '@/mixins/PageListMixin'
import { filterObj } from '@/utils/util'
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import contractAdd from'./modules/contractAdd'
import { postAction,getAction } from '../../../api/manage'
//高级查询modal需要参数

export default {
  name: 'contract',
  mixins: [PageListMixin],
  components: {
    JSuperQuery,
    JInput,
    JTreeSelect,
    contractAdd,
  },
  data() {
    return {
      description: '合同配置',
      //字典数组缓存
      sexDictOptions: [],
      importExcelUrl: `${window._CONFIG['domianURL']}/test/cn-formDemo/importExcel`,

      //搜索区域
      searchConfig: [
        {
          type: 'input',
          name: 'contractCode',
          placeholder: '请输入合同编号'
        },
        {
          type: 'input',
          name: 'contractName',
          placeholder: '请输入合同名称'
        },
        {
          type: 'input',
          name: 'custCode',
          placeholder: '请输入经销商编号'
        },
        {
          type: 'input',
          name: 'custName',
          placeholder: '请输入经销商名称'
        },
      ],
      ////表头
      columns: [
        {
          width:60,
          fixed: 'left',
          type:'checkbox',
        },
        {
          title: '合同编号',
          minWidth:80,
          field: 'contractCode',
          ellipsis: true,
          scopedSlots: {customRender: 'contractCode'},
        },
        {
          title: '合同名称',
          minWidth:80,
          field: 'contractName',
          scopedSlots: { customRender: 'contractName' }
        },
        {
          title: '年度',
          minWidth:80,
          field: 'contractYear'
        },
        {
          title: '经销商编号',
          minWidth:80,
          field: 'custCode',
        },
        {
          title: '经销商名称',
          minWidth:80,
          field: 'custName'
        },
        {
          title: '开始时间',
          minWidth:80,
          field: 'startDate',
        },
        {
          title: '结束时间',
          minWidth:80,
          field: 'endDate'
        },
        {
          title: '创建人',
          minWidth:80,
          field: 'createName'
        },

        {
          title: '创建时间',
          minWidth:80,
          field: 'createTime'
        },
        {
          title: '最近更新人',
          minWidth:100,
          field: 'updateName',
          ellipsis: true
        },
        {
          title: '最近更新时间',
          minWidth:120,
          field: 'updateTime',
          ellipsis: true,
        },
        {
          title: '操作',
          field: 'action',
          fixed: 'right',
          minWidth:80,
          slots: { default: 'action' },
        }
      ],
      url: {
        list: window._CONFIG['domianDmsURL'] + '/dmsContractController/getPageList',
        delete: window._CONFIG['domianDmsURL'] + '/dmsContractController/deleteById',
        detail:window._CONFIG['domianDmsURL'] +'/dmsContractController/getInfo',
        deleteBatch: '/test/cn-formDemo/deleteBatch',
        exportXlsUrl: '/test/cn-formDemo/exportXls'
      }

    }
  },
  methods: {
    lickTodetail(id,status){
      getAction(this.url.detail, { id: id }).then(res =>{

        this.$refs.modalForm.edit(res.result,status)
      })
    },
    selectCusttype(value) {
      this.$set(this.queryParam, 'custType', value)
    },
    getQueryParams() {
      //高级查询器
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

      param.field = this.getQueryField()
      param.current = this.ipagination.current
      param.size = this.ipagination.pageSize
      delete param.birthdayRange //范围参数不传递后台
      return filterObj(param)
    },
    // initDictConfig() {
    //   console.log("--我才是真的方法!--")
    //初始化字典 - 性别
    // initDictOptions('sex').then((res) => {
    //   if (res.success) {
    //     this.sexDictOptions = res.result;
    //   }
    // });
    // },
    //跳转单据页面
    jump() {
      this.$notification.success('跳转 ： jump')
    },
    onBirthdayChange: function(value, dateString) {
      console.log(dateString[0], dateString[1])
      this.queryParam.birthday_begin = dateString[0]
      this.queryParam.birthday_end = dateString[1]
    },
  },
  created() {
  }

}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>